﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Help;
using Model;
using System.Data;
namespace BLLA
{
    public partial class Order_FlowPay_T : BaseBLL<Model.Order_FlowPay_T>, IBLL.IOrder_FlowPay_TBLL
    {
        ObjectSerialize os = new ObjectSerialize();
        DataResult result = new DataResult();
        /// <summary>
        /// 获取所有流水
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页面大小</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：json；2：xml）</param>
        /// <returns></returns>
        public string GetOrder_FlowPay(int pageIndex, int pageSize, string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
            #region 业务层
            List<Model.View_FlowPay> mo = new List<Model.View_FlowPay>();
            try
            {

                mo = base.DBSession.IView_FlowPayDAL.GetListBy(u => u.AccID > 0);
            }
            catch (Exception)
            {
                result.BS = "-1";
                result.Msg = "查询不到数据！";
                return os.StringOfObject(result, RETID);
            }
            result.BS = "1";
            result.Msg = "查询成功！";
            result.total = mo.Count;
            result.rows = mo.Skip((pageIndex - 1) * pageSize).Take(pageSize);

            return os.StringOfObject(result, RETID);
            #endregion
        }

        /// <summary>
        /// 模糊查询第三方支付流水
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="AccName">名字</param>
        /// <param name="AccCall">电话</param>
        /// <param name="AccIdentifier">个人编号</param>
        /// <param name="PayFlowType">流水类型，Basic_Dict_T字典表DictId=30，DictKey值</param>
        /// <param name="PayID">支付类型，Order_Pay_T表，PayID值</param>
        /// <param name="PayFlowTime">发生时间，yyyyMMdd</param>
        /// <param name="YZM"></param>
        /// <param name="RETID"></param>
        /// <returns></returns>
        public string GetOrder_FlowPayByPara(int pageIndex, int pageSize, string AccName, string AccCall, string AccNum, string PayFlowType, string PayID, string PayFlowTime, string EFlowTime, string YZM, int RETID)
        {
            try
            {
                #region 匹配验证码
                if (YZM != Help.ALL_DataV.YZM)
                {
                    result.BS = "-88";
                    result.Msg = "验证码错误！";
                    return os.StringOfObject(result, RETID);
                }
                #endregion
                #region 业务层
                List<Model.View_FlowPay> mo = new List<Model.View_FlowPay>();
                StringBuilder sql = new StringBuilder();
                sql.Append("SELECT * FROM  View_FlowPay  where   1=1");
                if (!string.IsNullOrEmpty(AccName))
                {
                    sql.Append(" and AccName like '%" + AccName + "%'");
                }
                if (!string.IsNullOrEmpty(AccCall))
                {
                    sql.Append(" and AccCall like '%" + AccCall + "%'");
                }
                if (!string.IsNullOrEmpty(AccNum))
                {
                    sql.Append(" and AccNum like '%" + AccNum + "%'");
                }
                if (!string.IsNullOrEmpty(PayFlowType))
                {
                    sql.Append(" and PayFlowType ='" + PayFlowType + "' ");
                }
                if (!string.IsNullOrEmpty(PayID))
                {
                    sql.Append(" and PayID ='" + PayID + "' ");
                }
                if (!string.IsNullOrEmpty(PayFlowTime))
                {
                    sql.Append(" and PayFlowTime >='" + PayFlowTime + "000000" + "'"); 
                }
                if (!string.IsNullOrEmpty(EFlowTime))
                {
                    sql.Append(" and PayFlowTime <= '" + EFlowTime + "235959" + "' ");
                }
                sql.Append(" order by PayFlowTime asc");
                //var predicate = PredicateBuilder.True<Model.View_FlowPay>(); 
                //if (!string.IsNullOrEmpty(AccName))
                //{
                //    predicate = predicate.And(p => p.AccName.Contains(AccName));
                //}
                //if (!string.IsNullOrEmpty(AccCall))
                //{
                //    predicate = predicate.And(p => p.AccCall == AccCall);
                //}
                //if (!string.IsNullOrEmpty(AccNum))
                //{
                //    predicate = predicate.And(p => p.AccNum.Contains(AccNum));
                //}
                //if (!string.IsNullOrEmpty(PayFlowType))
                //{
                //    predicate = predicate.And(p => p.PayFlowType == PayFlowType);
                //}
                //if (!string.IsNullOrEmpty(PayID))
                //{
                //    predicate = predicate.And(p => p.PayID == PayID);
                //}
                //if (!string.IsNullOrEmpty(PayFlowTime))
                //{
                //    predicate = predicate.And(p => int.Parse(p.PayFlowTime.Substring(0, 8)) >= int.Parse(PayFlowTime));
                //}
                //if (!string.IsNullOrEmpty(EFlowTime))
                //{
                //    predicate = predicate.And(p => int.Parse(p.PayFlowTime.Substring(0, 8)) <= int.Parse(EFlowTime));
                //}
                int tol = 0; 
                mo = base.DBSession.IView_FlowPayDAL.GetListBy(sql.ToString());
                //mo = base.DBSession.IView_FlowPayDAL.GetPagedList<string>(pageIndex, pageSize, ref tol, predicate, u => u.PayFlowTime, false);
                if (mo != null && mo.Count > 0)
                {
                    result.BS = "1";
                    result.Msg = "查询成功！";
                    result.total = mo.Count;
                    result.rows = mo.Skip((pageIndex - 1) * pageSize).Take(pageSize); ;
                }
                else
                {
                    result.BS = "0";
                    result.Msg = "没有数据";
                    result.total = 0;
                    result.rows = null;
                }
                #endregion
            }

            catch (Exception ex)
            {
                WriteLog.WriteW("GetOrder_FlowPayByPara    获取钱包流水列表失败：" + ex.Message);
                result.BS = "-1";
                result.Msg = "查询不到数据！";
            }
            return os.StringOfObject(result, RETID);

        }





    }
}
